/** Concrete implementation of the Filter interface
 *  used to filter Property objects from a Repository
 *
 *  @author Scott Monahan
 *  @version $Id$
 *  
 *  File last changed on $Date:$ by $Author:$ in $Rev:$
 *
 */

package info637.pprc.repository;

import info637.pprc.model.Property;

public class PublicPropertyFilter extends AbstractPropertyFilter {

	public PublicPropertyFilter(Property property) {
		
		super(property);
	}

	public boolean matches(Property in) {

		boolean retVal = false;
		
		if (in.getShowOnline().equalsIgnoreCase("1")) {
			
			retVal = true;
			
			if (this.property.getAddress() != null && this.property.getAddress().length() > 0) {
				
				if (!in.getAddress().contains(this.property.getAddress())) {
					
					retVal = false;
				}
			}
			
			if (retVal && (this.property.getCity() != null && this.property.getCity().length() > 0)) {
				
				if (!in.getCity().contains(this.property.getCity())) {
					
					retVal = false;
				}
			}
			
			if (retVal && (this.property.getState() != null && this.property.getState().length() > 0)) {
				
				if (!in.getState().contains(this.property.getState())) {
					
					retVal = false;
				}
			}
			
			if (retVal && (this.property.getZip() != null && this.property.getZip().length() > 0)) {
				
				if (!in.getZip().contains(this.property.getZip())) {
					
					retVal = false;
				}
			}
			
			if (retVal && (this.property.getMonthlyRent() != null && this.property.getMonthlyRent().length() > 0)) {
				
				Long searchRent = Long.parseLong(this.property.getMonthlyRent());
				Long propertyRent = Long.parseLong(in.getMonthlyRent());
				
				if (searchRent <= propertyRent) {
					
					retVal = false;
				}
			}
		}
		
		return retVal;
	}
}
